using MicroMsg.Common.Utils;
using Microsoft.Phone.Data.Linq.Mapping;
using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
namespace MicroMsg.Storage
{
	[Index(Columns = "strObjectID DESC ", IsUnique = false, Name = "strObjectID"), Index(Columns = "nObjectStyle", IsUnique = false, Name = "nObjectStyle"), Table]
	public class SnsInfo : StorageItem
	{
		public TimeLineObject timeLine;
		private SnsCommentList _likeList;
		private SnsCommentList _commentList;
		private SnsCommentList _withList;
		private SnsGroupList _groupList;
		[Column(IsPrimaryKey = true, IsDbGenerated = true)]
		public int nLocalID;
		[Column]
		public int nCheckSum;
		[Column]
		public int nStatus;
		[Column]
		public int nObjectStyle;
		[Column]
		public string strObjectID;
		[Column]
		public string strUserName;
		[Column]
		public string strNickName;
		[Column]
		public uint nCreateTime;
		[Column]
		public int nLikeFlag;
		[Column]
		public uint nExtFlag;
		[Column]
		public int nLikeCount;
		[Column]
		public int nCommentCount;
		[Column]
		public int nWithUserCount;
		[Column(DbType = "Image")]
		public byte[] bytesXmlLikeList;
		[Column(DbType = "Image")]
		public byte[] bytesXmlCommnetList;
		[Column(DbType = "Image")]
		public byte[] bytesXmlWithList;
		[Column(DbType = "Image")]
		public byte[] bytesObjectDesc;
		[Column(DbType = "Image")]
		public byte[] bytesXmlGroupList;
		[Column(CanBeNull = true)]
		public int? pIsRichText;
		[Column(IsVersion = true)]
		private Binary _version;
		public SnsCommentList likeList
		{
			get
			{
				if (this._likeList != null)
				{
					return this._likeList;
				}
				if (this.bytesXmlLikeList != null)
				{
					this._likeList = StorageXml.loadFromBuffer<SnsCommentList>(this.bytesXmlLikeList);
				}
				if (this._likeList == null)
				{
					this._likeList = new SnsCommentList();
				}
				return this._likeList;
			}
			set
			{
				this._likeList = value;
				this.likeListFlush();
			}
		}
		public SnsCommentList commentList
		{
			get
			{
				if (this._commentList != null)
				{
					return this._commentList;
				}
				if (this.bytesXmlCommnetList != null)
				{
					this._commentList = StorageXml.loadFromBuffer<SnsCommentList>(this.bytesXmlCommnetList);
				}
				if (this._commentList == null)
				{
					this._commentList = new SnsCommentList();
				}
				return this._commentList;
			}
			set
			{
				this._commentList = value;
				this.commentListFlush();
			}
		}
		public SnsCommentList withList
		{
			get
			{
				if (this._withList != null)
				{
					return this._withList;
				}
				if (this.bytesXmlWithList != null)
				{
					this._withList = StorageXml.loadFromBuffer<SnsCommentList>(this.bytesXmlWithList);
				}
				if (this._withList == null)
				{
					this._withList = new SnsCommentList();
				}
				return this._withList;
			}
			set
			{
				this._withList = value;
				this.withListFlush();
			}
		}
		public SnsGroupList groupList
		{
			get
			{
				if (this._groupList != null)
				{
					return this._groupList;
				}
				if (this.bytesXmlGroupList != null)
				{
					this._groupList = StorageXml.loadFromBuffer<SnsGroupList>(this.bytesXmlGroupList);
				}
				if (this._groupList == null)
				{
					this._groupList = new SnsGroupList();
				}
				return this._groupList;
			}
			set
			{
				this._groupList = value;
				this.groupListFlush();
			}
		}
		public int nIsRichText
		{
			get
			{
				int? num = this.pIsRichText;
				if (!num.get_HasValue())
				{
					return 0;
				}
				return num.GetValueOrDefault();
			}
			set
			{
				this.pIsRichText = new int?(value);
			}
		}
		public ulong nObjectID
		{
			get
			{
				if (this.strObjectID == null)
				{
					return 0uL;
				}
				return SnsInfo.toID(this.strObjectID);
			}
			set
			{
				this.strObjectID = SnsInfo.toStrID(value);
			}
		}
		public void likeListFlush()
		{
			if (this._likeList != null && this._likeList.list.get_Count() > 0)
			{
				this.bytesXmlLikeList = StorageXml.saveToBuffer<SnsCommentList>(this._likeList);
				return;
			}
			this.bytesXmlLikeList = null;
		}
		public void commentListFlush()
		{
			if (this._commentList != null && this._commentList.list.get_Count() > 0)
			{
				this.bytesXmlCommnetList = StorageXml.saveToBuffer<SnsCommentList>(this._commentList);
				return;
			}
			this.bytesXmlCommnetList = null;
		}
		public void withListFlush()
		{
			if (this._withList != null && this._withList.list.get_Count() > 0)
			{
				this.bytesXmlWithList = StorageXml.saveToBuffer<SnsCommentList>(this._withList);
				return;
			}
			this.bytesXmlWithList = null;
		}
		public void groupListFlush()
		{
			if (this._groupList != null && this._groupList.list.get_Count() > 0)
			{
				this.bytesXmlGroupList = StorageXml.saveToBuffer<SnsGroupList>(this._groupList);
				return;
			}
			this.bytesXmlGroupList = null;
		}
		public static string toStrID(ulong nID)
		{
			return nID.ToString("X16");
		}
		public static ulong toID(string strID)
		{
			return Convert.ToUInt64(strID, 16);
		}
		public TimeLineObject getTimeLine()
		{
			if (this.timeLine != null)
			{
				return this.timeLine;
			}
			this.timeLine = TimeLineObject.ParseFrom(this.bytesObjectDesc);
			if (this.timeLine == null)
			{
				Log.smethod_1("SnsInfo", "parse xml error sns obj id=" + this.nObjectID);
				TimeLineObject.dumpXmlData(this.bytesObjectDesc);
			}
			return this.timeLine;
		}
		public void setTimeLine(TimeLineObject timeLineObject_0)
		{
			this.bytesObjectDesc = timeLineObject_0.toXmlData();
			this.timeLine = timeLineObject_0;
		}
		public bool setPrivacy(bool bPrivacy)
		{
			if (this.getTimeLine() == null)
			{
				return false;
			}
			if (bPrivacy && this.timeLine.nPrivate == 1)
			{
				return false;
			}
			if (!bPrivacy && this.timeLine.nPrivate == 0)
			{
				return false;
			}
			this.timeLine.nPrivate = (bPrivacy ? 1 : 0);
			this.bytesObjectDesc = this.timeLine.toXmlData();
			return true;
		}
		public bool isPrivate()
		{
			return this.getTimeLine() != null && this.timeLine.nPrivate == 1;
		}
		public bool deleteSnsComment(int commentID)
		{
			bool result;
			using (List<SnsComment>.Enumerator enumerator = this.commentList.list.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					SnsComment current = enumerator.get_Current();
					if (current.nCommentId == commentID)
					{
						this.commentList.list.Remove(current);
						this.commentListFlush();
						result = true;
						return result;
					}
				}
				return false;
			}
			return result;
		}
		public bool setLikeFlag(bool bLike, string name = null)
		{
			if (bLike && this.nLikeFlag == 1)
			{
				return false;
			}
			if (!bLike && this.nLikeFlag == 0)
			{
				return false;
			}
			this.nLikeFlag = (bLike ? 1 : 0);
			if (string.IsNullOrEmpty(name))
			{
				return true;
			}
			if (bLike)
			{
				this.likeList.list.Add(new SnsComment
				{
					strUserName = name
				});
				this.likeListFlush();
			}
			else
			{
				using (List<SnsComment>.Enumerator enumerator = this.likeList.list.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						SnsComment current = enumerator.get_Current();
						if (current.strUserName == name)
						{
							this.likeList.list.Remove(current);
							this.likeListFlush();
							break;
						}
					}
				}
			}
			return true;
		}
		public void dumpXml()
		{
		}
		public override void merge(object object_0)
		{
			SnsInfo snsInfo = object_0 as SnsInfo;
			this.nCheckSum = snsInfo.nCheckSum;
			this.nStatus = snsInfo.nStatus;
			this.nObjectStyle = snsInfo.nObjectStyle;
			this.strObjectID = snsInfo.strObjectID;
			this.strUserName = snsInfo.strUserName;
			this.strNickName = snsInfo.strNickName;
			this.nCreateTime = snsInfo.nCreateTime;
			this.nLikeFlag = snsInfo.nLikeFlag;
			this.nExtFlag = snsInfo.nExtFlag;
			this.nLikeCount = snsInfo.nLikeCount;
			this.nCommentCount = snsInfo.nCommentCount;
			this.nWithUserCount = snsInfo.nWithUserCount;
			this.bytesXmlLikeList = snsInfo.bytesXmlLikeList;
			this.bytesXmlCommnetList = snsInfo.bytesXmlCommnetList;
			this.bytesXmlWithList = snsInfo.bytesXmlWithList;
			this.bytesObjectDesc = snsInfo.bytesObjectDesc;
			this.bytesXmlGroupList = snsInfo.bytesXmlGroupList;
			this._likeList = null;
			this._commentList = null;
			this._withList = null;
			this._groupList = null;
			this.timeLine = null;
		}
	}
}
